package com.example.novel.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.novel.domain.Result;
import com.example.novel.domain.Subscribe;
import com.example.novel.service.SubscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/subscribe")
public class SubscribeController {

    @Autowired
    private SubscribeService subscribeService;

//    @ResponseBody
//    @RequestMapping("/getSubscribeBy/{userId}/{bookId}")//获取订阅状态
//    public Result getSubscribeBy(@PathVariable String userId, @PathVariable String bookId) {
//        Result result = new Result();
//            Subscribe subscribe = subscribeService.query().eq("user_id", userId).eq("book_id", bookId).one();
//            result.setCode(200);
//            result.setMsg("查询成功");
//            if (subscribe != null) {
//                result.setData("YES");
//            }else {
//                result.setData("NO");
//            }
//        return result;
//    }
//
//    @ResponseBody
//    @RequestMapping("/saveSubscribe/{userId}/{bookId}")
//    public Result saveSubscribe(@PathVariable Integer userId, @PathVariable Integer bookId) {
//        Result result = new Result();
//        Subscribe subscribe = new Subscribe();
//        subscribe.setUserId(userId);
//        subscribe.setBookId(bookId);
//        subscribeService.save(subscribe);
//        result.setCode(200);
//        result.setMsg("订阅成功");
//        return result;
//    }
//
//    @ResponseBody
//    @RequestMapping("/deleteSubscribe/{userId}/{bookId}")
//    public Result deleteSubscribe(@PathVariable Integer userId, @PathVariable Integer bookId) {
//        Result result = new Result();
//        LambdaQueryWrapper<Subscribe> wrapper = new LambdaQueryWrapper<Subscribe>()
//                .eq(Subscribe::getUserId, userId)
//                .eq(Subscribe::getBookId, bookId);
//        subscribeService.remove(wrapper);
//        result.setCode(200);
//        result.setMsg("取消订阅成功");
//        return result;
//    }

}
